package com.warm.androidstudy.view.ratingBar;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.RatingBar;

import com.warm.androidstudy.R;

public class RatingBarActivity extends AppCompatActivity {
    private RatingBar ratingBar;
    private StarView starView;
    private RatingBarView ratingBar_view;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rating_bar);
        ratingBar = findViewById(R.id.ratingBar);
        starView = findViewById(R.id.start_view);
        ratingBar_view  = findViewById(R.id.ratingBar_view);
        ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                Log.e("gsm",rating+"");
                Log.e("gsm",fromUser+"");
                int ran =(int) rating;
                for (int i = 0; i < ran; i++) {
                    starView.setAnim(i+1);
                }


                //创建缩放动画对象
//                Animation animation = new ScaleAnimation(0, 1.0f, 0f, 1.0f);
//                animation.setDuration(1500);//动画时间
//                animation.setRepeatCount(3);//动画的反复次数
//                animation.setFillAfter(true);//设置为true，动画转化结束后被应用
//                ratingBar.startAnimation(animation);//開始动画
                Animation animation = AnimationUtils.loadAnimation(RatingBarActivity.this, R.anim.scale);
                ratingBar.startAnimation(animation);//開始动画

//                //缩放动画
//                ScaleAnimation animation = new ScaleAnimation(1,1.2f,1,1.2f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
//                animation.setDuration(100);
//                animation.setFillAfter(true);
//                animation.setRepeatMode(Animation.REVERSE);
//                animation.setRepeatCount(1);
//
//                //透明度动画
//                AlphaAnimation animation1 = new AlphaAnimation(1,0.8f);
//                animation1.setDuration(100);
//                animation1.setRepeatCount(1);
//                animation1.setRepeatMode(Animation.REVERSE);
//                animation1.setFillAfter(true);
//
//                //装入AnimationSet中
//                AnimationSet set = new AnimationSet(true);
//                set.addAnimation(animation);
//                set.addAnimation(animation1);
//
//                if (ratingBar != null){
//                    ratingBar.startAnimation(set);
//                }
            }
        });
        ratingBar_view.setOnChangeListener(new RatingBarView.OnStarChangeListener() {
            @Override
            public void onStarChange(float selectNum, int position) {

            }
        });
    }
}